/*******************************************************************************
*  Project      : Minigate Golfin                                 
*  Program ID   : field_write.js                                 
*  Description  : 필드 글쓰기 
*
********************************************************************************
*  Program History                                                            
*  Date        Author    Description                                          
*  ----------  --------  -------------------------------------------------------- 
*  2012-04-23  김효순    Created.  
*  2012-04-23  김효순    Complete.  
*******************************************************************************/

jQuery(function($){
	// 댓글
	function clsCommentList($layer)
	{
		this._HTMLDom = {
			"$layer": $layer
			, "$element": $layer.find("dl:first").clone(true)
		};
		this.listData = null;
		
		this._init();
	}
	
	clsCommentList.prototype = {
		_init: function(){
			this._HTMLDom["$layer"].find("dl").remove();
		}
		, setList: function(thisData){
			this.listData = thisData;
			this.display();
		}
		, display: function(){
			var $layer = this._HTMLDom["$layer"];
			var $element = this._HTMLDom["$element"];
			var thisClass = this;
			
			$layer.find("dl").remove();
			for(var i=0;i<this.listData.length;i++){
				$layer.append($element.clone(true));
			}
			
			$layer.find("dl").each(function(n){
				$(this).find("dt:first img").attr("src", thisClass.listData[n]["이미지"]);
				$(this).find("span.nickname").html(thisClass.listData[n]["닉네임"]).next().html(thisClass.listData[n]["내용"]); 
				$(this).find("div.reply_in").html(thisClass.listData[n]["작성일"]).next("div.reply_in").html(thisClass.listData[n]["작성시"]);
				// 나이스샷
				if(thisClass.listData[n]["나이스샷"].length){
					$(this).find("div.reply_nice").html("나이스샷(" + thisClass.listData[n]["나이스샷"].length + ")").mouseenter(function(event){
						document.objGlobal.objMemberLayer.open(event, thisClass.listData[n]["나이스샷"], "right", 50, 0);
					}).mouseleave(function(){
						document.objGlobal.objMemberLayer.hide();
					})
				}else{
					$(this).find("div.reply_nice>span:first").hide();
				}
			});
		}
	}
	
	// 필드 리스트
	function clsFieldList()
	{
		this._HTMLDom = null;
		this.listData = null;
		
		this._init();
	}
	
	clsFieldList.prototype = {
		_init: function(){
			var $layer = $("div#container section#main_content article.all_field");
			this._HTMLDom = {
				"$layer": $layer
				, "$element": $layer.find("div.allfield_list").clone(true)
			}
			
			$layer.find("div.allfield_list").remove();
		}
		, setList: function(thisData){
			this.listData = thisData;
			
			this.display();
		}
		, display: function(){
			var $layer = this._HTMLDom["$layer"];
			var $element = this._HTMLDom["$element"];
			var thisClass = this;
			
			$layer.find("div.allfield_list").remove();
			for(var i=0;i<this.listData.length;i++){
				$layer.find("div.allfield_invite").before($element.clone(true));
			}
			
			$layer.find("div.allfield_list").each(function(n){
				var $thisElement = $(this);
				$(this).data("objComment", new clsCommentList($(this).find("div.reply_area")));
				
				// 섬네일
				$(this).find("div.f_photo").attr("src", thisClass.listData[n]["이미지"]);
				// 닉네임
				$(this).find("dl.f_detail div.nickname_cont a:first").html(thisClass.listData[n]["방장정보"]["닉네임"]).mouseenter(function(event){
					document.objGlobal.objProfileLayer.open(event, thisClass.listData[n]["방장정보"], "right", 50, 0);
				}).mouseleave(function(){
					document.objGlobal.objProfileLayer.hide();
				});
				//동호회
				if(thisClass.listData[n]["동호회키"]){
					$(this).find("div.cliub_go a").html(thisClass.listData[n]["동호회명"]).click(function(event){
						event.preventDefault();
						
						window.open("../self_club/home.html?q_seq=" + thisClass.listData[n]["동호회키"]);
					});;
				}else{
					$(this).find("div.cliub_go").hide();
				}
				// 날짜
				$(this).find("div.f_date span:first").html(thisClass.listData[n]["작성일"]).next().html(thisClass.listData[n]["작성시"]);
				// 메뉴화살표
				if(thisClass.listData[n]["자기글여부"] == "Y"){
					$(this).hover(function(){
						$thisElement.find("div.allfield_my").toggle();
					});
				}
				$(this).find("div.allfield_my").hide().find("p.my_bt img").hover(function(event){
					$thisElement.find("div.allfield_my ul.my_link").toggle();
				});
				
				$(this).find("div.allfield_my ul.my_link").hover(function(event){
					$thisElement.find("div.allfield_my ul.my_link").toggle();
				});
				
				// 메뉴레이어
				$(this).find("div.allfield_my ul.my_link").hide();
				// 내용
				$(this).find("dl.f_detail dd:first div:first").html(thisClass.listData[n]["내용"]);
				// 첨부이미지
				if(thisClass.listData[n]["첨부이미지"]){
					$(this).find("dl.f_detail dd:first div:first").append("<img src='" + thisClass.listData[n]["첨부이미지"] + "' />");
				}
				// 언급
				if(thisClass.listData[n]["언급자"].length > 0){
					if(thisClass.listData[n]["언급자"].length == 1){
						$(this).find("div.mention").html("<span>" + thisClass.listData[n]["언급자"][0]["닉네임"] + "</span> 님을 언급하였습니다.");
					}else{
						$(this).find("div.mention>span:first").html(thisClass.listData[n]["언급자"][0]["닉네임"]);
						$(this).find("div.mention>span:eq(1)").html(thisClass.listData[n]["언급자"].length).mouseenter(function(event){
							document.objGlobal.objMemberLayer.open(event, thisClass.listData[n]["언급자"], "right", 0, 0);
						}).mouseleave(function(){
							document.objGlobal.objMemberLayer.hide();
						});
					}
				}else{
					$(this).find("div.mention").hide();
				}
				
				// 나이스샷
				$(this).find("div.foot_link>p.f_link:last").html("나이스샷(" + thisClass.listData[n]["나이스샷"].length + ")");
				if(thisClass.listData[n]["나이스샷"].length > 0){
					if(thisClass.listData[n]["나이스샷"].length == 1){
						$(this).find("div.n_shot").html("<span>" + thisClass.listData[n]["나이스샷"][0]["닉네임"] + "</span> 님이 나이스샷을 외치셨습니다.");
					}else{
						$(this).find("div.n_shot>span:first").html(thisClass.listData[n]["나이스샷"][0]["닉네임"]);
						$(this).find("div.n_shot>span.po:first>a:first").html(thisClass.listData[n]["나이스샷"].length).mouseenter(function(event){
							document.objGlobal.objMemberLayer.open(event, thisClass.listData[n]["나이스샷"], "right", 0, 0);
						}).mouseleave(function(){
							document.objGlobal.objMemberLayer.hide();
						});
					}
				}else{
					$(this).find("div.n_shot").hide();
				}
				
				// 댓글달기
				$(this).find("div.reply_regist a").click(function(event){
					event.preventDefault();
					
					//thisClass.commentSubmit();
				});
			});
		}
		, setCommentList: function(fieldKey, thisData){
			var $layer = this._HTMLDom["$layer"];
			for(var i=0;i<this.listData.length;i++){
				if(this.listData[i]["키"] == fieldKey) break;
			}
			
			if(i >= this.listData.length) return;
			
			$layer.find("div.allfield_list:eq(" + i + ")").data("objComment").setList(thisData);
		}
	}
	
	// 초대정보 리스트
	function clsInviteList()
	{
		this._HTMLDom = null;
		this.listData = null;
		
		this._init();
	}
	
	clsInviteList.prototype = {
		_init: function(){
			var $layer = $("div#container article.all_field div.allfield_invite");
			this._HTMLDom = {
				"$layer": $layer
				, "$element": $layer.find("dl:first").clone(true)
			}
			
			$layer.find("dl").remove();
		}
		, setList: function(thisData){
			this.listData = thisData;
			this.display();
		}
		, display: function(){
			var $layer = this._HTMLDom["$layer"];
			var $element = this._HTMLDom["$element"];
			var thisClass = this;
			
			$layer.find("dl").remove();
			for(var i=0;i<this.listData.length;i++){
				$layer.append($element.clone(true));
			}
			
			$layer.find("dl").each(function(n){
				// 이미지
				$(this).find("dt:first>img").attr("src", thisClass.listData[n]["등록자"]["이미지"]);
				// 닉네임
				$(this).find("div.nickname>a:first").html(thisClass.listData[n]["등록자"]["닉네임"]).mouseenter(function(event){
					document.objGlobal.objProfileLayer.open(event, thisClass.listData[n]["등록자"], "right", 30, 0);
				}).mouseleave(function(){
					document.objGlobal.objProfileLayer.hide();
				});
				// 날짜
				$(this).find("p.invite_date>span:eq(0)").html(thisClass.listData[n]["날짜"]).next("span").html(thisClass.listData[n]["시간"]);
				$(this).find("div.dis_bl").html(thisClass.listData[n]["내용"]);
			});
		}
	}
	
	// 나의 그룹
	function clsGroupList()
	{
		this._HTMLDom = null;
		this.listData = null;
		
		this._init();
	}
	
	clsGroupList.prototype = {
		_init: function(){
			var $layer = $("div#container section#main_content dl.friend_cont dt:first");
			this._HTMLDom = {
				"$layer": $layer
				, "$element": $layer.find("li:first").clone(true)
			}
			
			this._HTMLDom["$layer"].find("div.all_list").hide();
			
			$layer.data("idx", null);
		}
		, setList: function(thisData){
			this.listData = thisData;
			this.display();
		}
		, display: function(){
			var $layer = this._HTMLDom["$layer"];
			var $element = this._HTMLDom["$element"];
			var thisClass = this;
			
			$layer.find("ul").empty();
			for(var i=0;i<this.listData.length;i++){
				$layer.find("ul").append($element.clone(true));
			}
			
			$layer.find("li a").each(function(n){
				$(this).html(thisClass.listData[n]["그룹명"] + "(" + thisClass.listData[n]["친구수"] + ")").click(function(event){
					event.preventDefault();
					
					thisClass.setIDX(n);
				});
			});
			
			$layer.find("div.all_list>p.tit:first").click(function(event){
				event.preventDefault();
				
				thisClass.setIDX(null);
			});
		}
		, displayTitle: function(){
			var $layer = this._HTMLDom["$layer"];
			var idx = $layer.data("idx");
			var szTit = (idx == null) ? "전체": this.listData[idx]["그룹명"];
			
			$layer.find("span.bt_all").html(szTit);
		}
		, setIDX: function(idx){
			this._HTMLDom["$layer"].data("idx", idx);
			this.hideGroup();
			this.displayTitle();
			
			$(this).trigger("evtGroupSelect");
		}
		, $getSelect: function(){
			var $layer = this._HTMLDom["$layer"];
			
			return $layer.find("span.bt_all ");
		}
		, showGroup: function(){
			var $layer = this._HTMLDom["$layer"];
			
			$layer.find("div.all_list").show(300);
		}
		, hideGroup: function(){
			var $layer = this._HTMLDom["$layer"];
			
			$layer.find("div.all_list").hide();
		}
		, getKey: function(){
			var $layer = this._HTMLDom["$layer"];
			var idx = $layer.data("idx");
			
			if(idx == null) return null;
			else return this.resData[idx]["key"];
		}
	}
	
	// 친구검색
	function clsFriendSearch()
	{
		this._HTMLDom = null
		
		this._init();
	}
	
	clsFriendSearch.prototype = {
		_init: function(){
			this._HTMLDom = {
				"$layer": $("div#container>section#main_content>aside.field_right>dl.friend_cont dd:first")
			}
		}
		, getValue: function(){
			var $layer = this._HTMLDom["$layer"];
			
			return $layer.find(":text").val();
		}
		, $getBtnSearch: function(){
			var $layer = this._HTMLDom["$layer"];
			
			return $layer.find(":image");
		}
	}
	
	// 친구목록
	function clsFriendList()
	{
		this._HTMLDom = null;
		this.listData = null;
		
		this._init();
	}
	
	clsFriendList.prototype = {
		_init: function(){
			var $layer = $("div#container>section#main_content>aside.field_right>dl.friend_cont dd.friend_list");
			this._HTMLDom = {
				"$layer": $layer
				, "$element": $layer.find("tr:first").clone(true)
			}
			$layer.find("tbody").empty();
		}
		, setList: function(thisData){
			this.listData = thisData;
			this.display();
		}
		, display: function(){
			var $layer = this._HTMLDom["$layer"];
			var $element = this._HTMLDom["$element"];
			var thisClass = this;
			
			$layer.find("tbody").empty();
			for(var i=0;i<this.listData.length;i++){
				$layer.find("tbody").append($element.clone(true));
			}
			$layer.find("tr").each(function(n){
				// 언급
				$(this).find("td:eq(0) img").click(function(event){
					event.preventDefault();
					
					$(thisClass).trigger("evtMentionClick", [thisClass.listData[n]]);
				});
				// 이미지
				$(this).find("td:eq(1) img").attr("src", thisClass.listData[n]["이미지"]);
				// 닉네임
				$(this).find("div.div_pos a").html(thisClass.listData[n]["닉네임"]).mouseenter(function(event){
					document.objGlobal.objProfileLayer.open(event, thisClass.listData[n], "left", -250, 0);
				}).mouseleave(function(){
					document.objGlobal.objProfileLayer.hide();
				});
				// 프로파일
				$(this).find("div.profile_layer02").show().find("div.profile_cont p.profile_phto>img").attr("src", thisClass.listData[n]["이미지"]).next("div.profile_cont");
			});
		}
	}
	
	// 글쓰기
	function clsFieldWrite()
	{
		this._HTMLDom = null;
		this.errMsg = null;
		
		// 언급자
		this.mentionList = null;
		// 첨부사진
		this.fileName = null;
		this._init();
	}
	
	clsFieldWrite.prototype = {
		_init:function(){
			var thisClass = this;
			
			this._HTMLDom = {
				"$layer": $("div#container section#main_content article.all_field div.allfield_write")
			}
			
			// 등록버튼 앞에 파일엘리먼트 추가
			this.$getBtnFileSubmit().before("<input type='file' style='position:absolute; width:0; height:0; border:0;'>").prev().change(function(event){
				$(thisClass).trigger("evtSelectFile");
			});
			
			this.reset();
		}
		, reset: function(){
			this.mentionList = [];
			this.fileName = null;
			
			this.displayMention();
			this.displayFile();
			this._HTMLDom["$layer"].find("textarea").val("");
			this._HTMLDom["$layer"].find("select>option:first").attr("selected", "selected");
		}
		, isValid: function(){
			var $layer = this._HTMLDom["$layer"];
			var szNote = $layer.find("textarea").val();
			
			if(!szNote){
				this.errMsg = "내용을 입력해 주십시요.";
				$layer.find("textarea").trigger("focus");
				return false;
			}
			
			return true;
			
		}
		, getError: function(){
			return this.errMsg;
		}
		// 언급자 추가
		, addMention: function(arg){
			for(var i=0;i<this.mentionList.length;i++){
				if(this.mentionList[i]["아이디"] == arg["아이디"]) break;
			}
			
			if(this.mentionList.length > 0 && i < this.mentionList.length) return;
			
			this.mentionList.push(arg)
			this.displayMention();
		}
		, displayMention: function(){
			var $layer = this._HTMLDom["$layer"];
			var $obj = $layer.find("p.nickname");
			var szMention = "";
			
			$obj.empty();
			
			for(var i=0;i<this.mentionList.length;i++){
				if(szMention) szMention += " ";
				szMention += "<span>" + this.mentionList[i]["닉네임"] + "</spna>";
			}
			
			$obj.append(szMention);
		}
		, displayFile: function(){
			var $layer = this._HTMLDom["$layer"];
			var $obj = $layer.find("li.pho_file");
			
			if(this.fileName){
				$obj.html(this.fileName).show();
			}else{
				$obj.hide();
			}
		}
		, $getBtnFileSubmit: function(){
			var $layer = this._HTMLDom["$layer"];
			
			return $layer.find("li:first a");
		}
		, $getBtnSubmit: function(){
			var $layer = this._HTMLDom["$layer"];
			
			return $layer.find("li.fr:first a");
		}
		, openFile: function(){
			var $layer = this._HTMLDom["$layer"];
			
			$layer.find(":file").trigger("click");
		}
		// 파일엘리먼트 값
		, getFileName: function(){
			var $layer = this._HTMLDom["$layer"];
			
			return $layer.find(":file").val();
		}
		// 첨부파일설정
		, setFile: function(val){
			this.fileName = val;
			this.displayFile();
		}
		// 첨부된 파일
		, getFile: function(val){
			return this.fileName;
		}
		// 언급자
		, getMentionList: function(){
			return this.mentionList;
		}
		// 내용
		, getNote: function(){
			var $layer = this._HTMLDom["$layer"];
			
			return $layer.find("textarea").val();
		}
		// 공개타입
		, getOpenType: function(){
			var $layer = this._HTMLDom["$layer"];
			
			return $layer.find("select option:selected").val();
		}
	}
	
	
	function clsComm()
	{
		this.fieldList = null;
		this.fieldRequest = null;
		
		this.commentList = null;
		
		this.inviteList = null;
		this.inviteRequest = null;
		
		this.groupList = null;
		
		this.friendList = null;
		this.friendRequest = null;
		
		this._init();
	}
	
	clsComm.prototype = {
		_init: function(){
			this.fieldList = [
				{
					"키": null
					, "이미지": null
					, "방장정보": {
						"이미지": null
						, "아이디": null
						, "닉네임": null
						, "성별": null
						, "핸디": null
						, "비거리": null
					}
					, "동호회키": null
					, "동호회명": null
					, "작성일": null
					, "작성시": null
					, "내용": null
					, "첨부이미지": null
					, "언급자": [
//						{
//							"아이디": null
//							, "이미지": null
//							, "닉네임": null
//						}
					]
					, "나이스샷": [
//						{
//							"아이디": null
//							, "이미지": null
//							, "닉네임": null
//						}
					]
					, "자기글여부": null
				}
			];
			
			this.fieldRequest = {
				"갯수": null
			}
			
			this.commentList = {
				"동호회 해당키": [
//					{
//						"키": null
//						, "이미지": null
//						, "아이디": null
//						, "닉네임": null
//						, "내용": null
//						, "작성일": null
//						, "작성시": null
//						, "나이스샷": [
//							{
//								"아이디": null
//								, "이미지": null
//								, "닉네임": null
//							}
//						]
//					}
				]
			}
			
			this.inviteList = [
//				{
//					"키": null
//					, "등록자": {
//						"아이디": null
//						, "이미지": null
//						, "닉네임": null
//						, "성별": null
//						, "핸디": null
//						, "비거리": null
//					}
//					, "날짜": null
//					, "시간": null
//					, "내용": null
//				}
			];
			
			this.inviteRequest = {
				"갯수": null
			}
			
			this.groupList = [
//				{
//					"키": null
//					, "그룹명": null
//					, "친구수": null
//				}
			];
			
			this.friendList = [
//				{
//					"아이디": null
//					, "닉네임": null
//					, "이미지": null
//					, "성별": null
//					, "핸디": null
//					, "비거리": null
//				}
			];
			
			this.friendRequest = {
				"그룹키": null
				, "검색어": null
				, "갯수": null
			}
		}
		, getFieldList: function(){
			var thisClass = this;
			// ajax
			
			setTimeout(function(){
				thisClass.fieldList  = [
					{
						"키": "001"
						, "이미지": "../images/board/default_50_50.gif"
						, "방장정보": {
							"이미지": "../images/board/default_100_100.gif"
							, "아이디": "sky72"
							, "닉네임": "잭니클라우스"
							, "성별": "여자"
							, "핸디": "109"
							, "비거리": "170"
						}
						, "동호회키": "001"
						, "동호회명": "홀인원하는 그날"
						, "작성일": "2012.01.10"
						, "작성시": "17:10"
						, "내용": "남녀 2쌍 커플로 갈만한 골프장 어디가 좋을까요 ? <br/>평일에 가보려고 하는데 ... 모두 골프는 중급정도 되고요 ... 	즐겁게 아침부터 저녁까지 치고, 근처에서 저녁에 식사 하고요...."
						, "첨부이미지": "../images/board/del.gif"
						, "언급자": [
							{
								"아이디": "sky72"
								, "이미지": "../images/board/default_35_35.gif"
								, "닉네임": "필드광1"
							}
							, {
								"아이디": "sky73"
								, "이미지": "../images/board/default_35_35.gif"
								, "닉네임": "필드광2"
							}
							, {
								"아이디": "sky74"
								, "이미지": "../images/board/default_35_35.gif"
								, "닉네임": "필드광3"
							}
						]
						, "나이스샷": [
							{
								"아이디": "sky72"
								, "이미지": "../images/board/default_35_35.gif"
								, "닉네임": "오스케 짱말짱1"
							}
							, {
								"아이디": "sky73"
								, "이미지": "../images/board/default_35_35.gif"
								, "닉네임": "오스케 짱말짱2"
							}
							, {
								"아이디": "sky74"
								, "이미지": "../images/board/default_35_35.gif"
								, "닉네임": "오스케 짱말짱3"
							}
						]
						, "자기글여부": "Y"
					}
					, {
						"키": "002"
						, "이미지": "../images/board/default_50_50.gif"
						, "방장정보": {
							"이미지": "../images/board/default_100_100.gif"
							, "아이디": "sky73"
							, "닉네임": "잭니클라우스1"
							, "성별": "여자"
							, "핸디": "119"
							, "비거리": "110"
						}
						, "동호회키": null
						, "동호회명": null
						, "작성일": "2012.01.10"
						, "작성시": "17:10"
						, "내용": "남녀 5쌍 커플로 갈만한 골프장 어디가 좋을까요 ? <br/>평일에 가보려고 하는데 ... 모두 골프는 중급정도 되고요 ... 	즐겁게 아침부터 저녁까지 치고, 근처에서 저녁에 식사 하고요...."
						, "첨부이미지": "../images/board/del.gif"
						, "언급자": [
							{
								"아이디": "sky72"
								, "이미지": "../images/board/default_35_35.gif"
								, "닉네임": "필드광1"
							}
							, {
								"아이디": "sky73"
								, "이미지": "../images/board/default_35_35.gif"
								, "닉네임": "필드광2"
							}
							, {
								"아이디": "sky74"
								, "이미지": "../images/board/default_35_35.gif"
								, "닉네임": "필드광3"
							}
						]
						, "나이스샷": [
							{
								"아이디": "sky72"
								, "이미지": "../images/board/default_35_35.gif"
								, "닉네임": "오스케 짱말짱1"
							}
							, {
								"아이디": "sky73"
								, "이미지": "../images/board/default_35_35.gif"
								, "닉네임": "오스케 짱말짱2"
							}
							, {
								"아이디": "sky74"
								, "이미지": "../images/board/default_35_35.gif"
								, "닉네임": "오스케 짱말짱3"
							}
						]
						, "자기글여부": "N"
					}
				];
				
				for(var i=0;i<thisClass.fieldList.length;i++){
					thisClass.getCommentList(thisClass.fieldList[i]["키"], 100);
				}
				
				$(thisClass).trigger("evtFinishFieldList");
			}, 1500);
		}
		, getFieldData: function(){
			return this.fieldList;
		}
		, setFieldRequest: function(key, val){
			this.fieldRequest[key] = val;
		}
		, getCommentList: function(fieldKey, cnt){
			var thisClass = this;
			// ajax
			
			setTimeout(function(){
				thisClass.commentList[fieldKey] = [
					{
						"키": "001"
						, "이미지": "../images/board/default_35_35.gif"
						, "아이디": "sky72"
						, "닉네임": "잭니클라우스우스"
						, "내용": "남녀 2쌍 커플로 갈만한 골프장 어디가 좋을까요? 남녀 2쌍 커플로 갈만한 골프장 어디가 좋을까요 ? 평일에 가보려고 하는데 ... 모두 골프는 중급정도 되고요 ..."
						, "작성일": "2012.03.31"
						, "작성시": "17:08"
						, "나이스샷": [
							{
								"아이디": "sky72"
								, "이미지": "../images/board/default_35_35.gif"
								, "닉네임": "오스케 짱말짱"
							}
							, {
								"아이디": "sky73"
								, "이미지": "../images/board/default_35_35.gif"
								, "닉네임": "오스케 짱말짱2"
							}
							, {
								"아이디": "sky74"
								, "이미지": "../images/board/default_35_35.gif"
								, "닉네임": "오스케 짱말짱3"
							}
							, {
								"아이디": "sky75"
								, "이미지": "../images/board/default_35_35.gif"
								, "닉네임": "오스케 짱말짱4"
							}
							, {
								"아이디": "sky76"
								, "이미지": "../images/board/default_35_35.gif"
								, "닉네임": "오스케 짱말짱5"
							}
						]
					}
					, {
						"키": "002"
						, "이미지": "../images/board/default_35_35.gif"
						, "아이디": "sky73"
						, "닉네임": "잭니클라우스우스1"
						, "내용": "남녀 5쌍 커플로 갈만한 골프장 어디가 좋을까요? 남녀 3쌍 커플로 갈만한 골프장 어디가 좋을까요 ? 평일에 가보려고 하는데 ... 모두 골프는 중급정도 되고요 ..."
						, "작성일": "2012.03.30"
						, "작성시": "19:08"
						, "나이스샷": [
							{
								"아이디": "sky72"
								, "이미지": "../images/board/default_35_35.gif"
								, "닉네임": "오스케 짱말짱"
							}
							, {
								"아이디": "sky73"
								, "이미지": "../images/board/default_35_35.gif"
								, "닉네임": "오스케 짱말짱2"
							}
							, {
								"아이디": "sky74"
								, "이미지": "../images/board/default_35_35.gif"
								, "닉네임": "오스케 짱말짱3"
							}
						]
					}
				];
				
				$(thisClass).trigger("evtFinishCommentList", [fieldKey]);
			}, 1500);
		}
		, getCommentData: function(fieldKey){
			return this.commentList[fieldKey];
		}
		, getInviteList: function(){
			var thisClass = this;
			
			//ajax
			setTimeout(function(){
				thisClass.inviteList = [
					{
						"키": "001"
						, "등록자": {
							"아이디": "sky71"
							, "이미지": "../images/board/default_50_50.gif"
							, "닉네임": "닉네임1"
							, "성별": "여자"
							, "핸디": 109
							, "비거리": 170
						}
						, "날짜": "2011.01.02"
						, "시간": "15:30"
						, "내용": "민수님멋쨍이님이 잭니클라우스님 외 3명을 2012.02,11 10:00 부킹 예약에 초대 하였습니다."
					}
					, {
						"키": "002"
						, "등록자": {
							"아이디": "sky72"
							, "이미지": "../images/board/default_50_50.gif"
							, "닉네임": "닉네임2"
							, "성별": "남자"
							, "핸디": 200
							, "비거리": 250
						}
						, "날짜": "2012.01.02"
						, "시간": "14:30"
						, "내용": "민수님멋쨍이님이 잭니클라우스님 외 56명을 2012.02,11 10:00 부킹 예약에 초대 하였습니다."
					}
				];
				
				$(thisClass).trigger("evtFinishInviteList");
			}, 1500);
		}
		, getInviteData: function(){
			return this.inviteList;
		}
		, setInviteRequest: function(key, val){
			this.inviteRequest[key] = val;
		}
		, getGroupList: function(){
			var thisClass = this;
			
			//ajax
			setTimeout(function(){
				thisClass.groupList = [
					{
						"키": "001"
						, "그룹명": "초등학교 동창"
						, "친구수": 3
					}
					, {
						"키": "002"
						, "그룹명": "중학교 동창"
						, "친구수": 4
					}
					, {
						"키": "003"
						, "그룹명": "고딩 동창"
						, "친구수": 5
					}
					, {
						"키": "004"
						, "그룹명": "대학 동창"
						, "친구수": 6
					}
					, {
						"키": "005"
						, "그룹명": "직장동료"
						, "친구수": 7
					}
				];
				
				$(thisClass).trigger("evtFinishGroupList");
			}, 1500);
		}
		, getGroupData: function(){
			return this.groupList;
		}
		, getFriendList: function(){
			var thisClass = this;
			
			//ajax
			setTimeout(function(){
				thisClass.friendList = [
					{
						"아이디": "sky72"
						, "이미지": "../images/board/default_35_35.gif"
						, "닉네임": "오스케 짱말짱1"
						, "성별": "여자"
						, "핸디": "110"
						, "비거리": "150"
					}
					, {
						"아이디": "sky73"
						, "이미지": "../images/board/default_35_35.gif"
						, "닉네임": "오스케 짱말짱2"
						, "성별": "여자"
						, "핸디": "115"
						, "비거리": "155"
					}
				];
				
				$(thisClass).trigger("evtFinishFriendList");
			}, 1500);
		}
		, getFriendData: function(){
			return this.friendList;
		}
		, setFriendRequest: function(key, val){
			this.friendRequest[key] = val;
		}
		// 필드 글쓰기
		, fieldSubmit: function(arg){
//			arg = {
//				"언급자": [
//					{
//						"아이디": null
//						, "닉네임": null
//					}
//				]
//				, "내용": null
//				, "첨부이미지": null
//				, "공개타입": null
//			}
			
			var thisClass = this;
			
			//ajax
			setTimeout(function(){
				var resData = {
					"성공여부": true
					, "리턴메시지": null
				}
				
				$(thisClass).trigger("evtFinishFieldSubmit", [resData]);
			}, 1500);
		}
		// 파일전송
		, fileSubmit: function(arg){
//			arg = {
//				"파일명": null
//			}

			// ajax
			var thisClass = this;
			
			//ajax
			setTimeout(function(){
				var resData = {
					"성공여부": true
					, "리턴메시지": "http://sstatic.naver.net/search/img3/h1_naver.gif"
				}
				
				$(thisClass).trigger("evtFinishFileSubmit", [resData]);
			}, 1500);
		}
	}
	
	
	// 컨트롤
	function clsControl()
	{
		this.objComm = null;
		this.objFieldList = null;
		this.objInviteList = null;
		this.objGroupList = null;
		this.objFriendList = null;
		this.objFriendSearch = null;
		this.objFieldWrite = null;
		
		this._init();
	}
	
	clsControl.prototype = {
		_init: function(){
			this.objComm = new clsComm();
			this.objFieldList = new clsFieldList();
			this.objInviteList = new clsInviteList();
			this.objGroupList = new clsGroupList();
			this.objFriendList = new clsFriendList();
			this.objFriendSearch = new clsFriendSearch();
			this.objFieldWrite = new clsFieldWrite();
			
			this._bind();
			
			// 필드 리스트
			this.objComm.setFieldRequest("갯수", 100);
			this.objComm.getFieldList();
			
			// 초대정보
			this.objComm.setInviteRequest("갯수", 100);
			this.objComm.getInviteList();
			
			
			// 친구목록내 그룹
			this.objComm.getGroupList();
			
			// 친구 리스트
			this.objComm.setFriendRequest("갯수", 100);
			this.objFriendSearch.$getBtnSearch().trigger("click");
			
		}
		, _bind: function(){
			var thisClass = this;
			
			$(this.objComm).bind("evtFinishFieldList", function(){
				var thisData = this.getFieldData();
				
				thisClass.objFieldList.setList(thisData);
			}).bind("evtFinishCommentList", function(event, fieldKey){
				var thisData = this.getCommentData(fieldKey);
				
				thisClass.objFieldList.setCommentList(fieldKey, thisData);
			}).bind("evtFinishInviteList", function(){
				var thisData = this.getInviteData();
				
				thisClass.objInviteList.setList(thisData);
			}).bind("evtFinishGroupList", function(){
				var thisData = this.getGroupData();
				
				thisClass.objGroupList.setList(thisData);
			}).bind("evtFinishFriendList", function(){
				var thisData = this.getFriendData();
				
				thisClass.objFriendList.setList(thisData);
			// 글쓰기 완료
			}).bind("evtFinishFieldSubmit", function(event, retData){
				document.objGlobal.spinEnd();
				
				if(retData["성공여부"]){
					thisClass.objFieldWrite.reset();
					thisClass.objComm.getFieldList();
				}else{
					alert(retData["리턴메시지"]);
				}
			// 파일전송완료
			}).bind("evtFinishFileSubmit", function(event, retData){
				document.objGlobal.spinEnd();
				
				if(retData["성공여부"]){
					thisClass.objFieldWrite.setFile(retData["리턴메시지"]);
				}else{
					alert(retData["리턴메시지"]);
				}
			});
			
			// 그룹펼침
			this.objGroupList.$getSelect().click(function(event){
				event.preventDefault();
				
				thisClass.objGroupList.showGroup();
			});
			
			// 친구검색
			this.objFriendSearch.$getBtnSearch().click(function(event){
				event.preventDefault();
				
				var searchText = thisClass.objFriendSearch.getValue();
				thisClass.objComm.setFriendRequest("검색어", searchText);
				thisClass.objComm.getFriendList();
			});
			
			// 언급
			$(this.objFriendList).bind("evtMentionClick", function(event, thisData){
				thisClass.objFieldWrite.addMention({
					"아이디": thisData["아이디"]
					, "닉네임": thisData["닉네임"]
				});
			});
			
			// 사진첨부
			this.objFieldWrite.$getBtnFileSubmit().click(function(event){
				event.preventDefault();
				
				thisClass.objFieldWrite.openFile();
			});
			
			// 첨부 파일선택
			$(this.objFieldWrite).bind("evtSelectFile", function(event){
				document.objGlobal.objModalLoading.setText("sending...");
				document.objGlobal.spinStart();
				thisClass.objComm.fileSubmit({
					"파일명": this.getFileName()
				});
			});
			
			// 글쓰기
			this.objFieldWrite.$getBtnSubmit().click(function(event){
				if(!thisClass.objFieldWrite.isValid()){
					alert(thisClass.objFieldWrite.getError());
					return;
				}
				
				document.objGlobal.spinStart();
				thisClass.objComm.fieldSubmit({
					"언급자": thisClass.objFieldWrite.getMentionList()
					, "내용": thisClass.objFieldWrite.getNote()
					, "첨부이미지": thisClass.objFieldWrite.getFile()
					, "공개타입": thisClass.objFieldWrite.getOpenType()
				});
			});
		}
	}
	
	document.objControl = new clsControl();
});